import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * memberRoleService - 角色分配service
 * @date: 2018-7-6


 */
import request from 'utils/request';
import { CPAAS_IAM, CPAAS_PLATFORM } from 'utils/config';
/**
 * 查询角色成员
 * @async
 * @function queryMembers
 * @param {object} params - 查询条件
 * @param {!number} [params.page = 0] - 数据页码
 * @param {!number} [params.size = 10] - 分页大小
 * @param {number} organizationId - 组织ID
 * @returns {object} fetch Promise
 */

export function queryMembers(_x, _x2) {
  return _queryMembers.apply(this, arguments);
}
/**
 * 查询角色成员数量及角色信息
 * @async
 * @function queryRolesLevelUserCount
 * @param {object} params - 查询条件
 * @param {number} organizationId - 组织ID
 * @returns {object} fetch Promise
 */

function _queryMembers() {
  _queryMembers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params, organizationId) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/").concat(organizationId === 0 ? '' : "".concat(organizationId, "/"), "member-roles/users/roles"), {
              query: params
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryMembers.apply(this, arguments);
}

export function queryRolesLevelUserCount() {
  return _queryRolesLevelUserCount.apply(this, arguments);
}
/**
 * 查询角色下的成员(roleId)
 * @async
 * @function queryRoles
 * @param {object} params - 查询条件
 * @param {!number} param.roleId - 角色ID
 * @param {number} organizationId - 组织ID
 * @returns {object} fetch Promise
 */

function _queryRolesLevelUserCount() {
  _queryRolesLevelUserCount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
    var params,
        organizationId,
        _args2 = arguments;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            params = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
            organizationId = _args2.length > 1 ? _args2[1] : undefined;
            return _context2.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/").concat(organizationId === 0 ? '' : "".concat(organizationId, "/"), "member-roles/roles/roles-with-usercount"), {
              body: params
            }));

          case 3:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _queryRolesLevelUserCount.apply(this, arguments);
}

export function queryRoles() {
  return _queryRoles.apply(this, arguments);
} // /**
//  * 校验成员是否存在
//  * @async
//  * @function queryUser
//  * @param {object} params - 查询条件
//  * @param {!string} param.condition - 查询条件(name/email/phone)
//  * @param {number} organizationId - 组织ID
//  * @returns {object} fetch Promise
//  */
// export async function queryUser(params, organizationId) {
//   return request(`${CPAAS_IAM}/cpaas/v1/${organizationId === 0 ? '' : `${organizationId}/`}users`, {
//     query: params,
//   });
// }

/**
 * 查询当前用户分配角色及子角色的集合列表
 * @async
 * @function queryCreateRolesSublist
 * @param {object} params - 查询条件
 * @param {!number} [params.page = 0] - 数据页码
 * @param {!number} [params.size = 10] - 分页大小
 * @param {number} organizationId - 组织ID
 * @returns {object} fetch Promise
 */

function _queryRoles() {
  _queryRoles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
    var params,
        organizationId,
        _args3 = arguments;
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            params = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {};
            organizationId = _args3.length > 1 ? _args3[1] : undefined;
            return _context3.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/").concat(organizationId === 0 ? '' : "".concat(organizationId, "/"), "member-roles/users"), {
              query: params
            }));

          case 3:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _queryRoles.apply(this, arguments);
}

export function queryCreateRolesSublist(_x3, _x4) {
  return _queryCreateRolesSublist.apply(this, arguments);
}
/**
 * 查询值集
 * @async
 * @function queryCode
 * @param {object} params - 查询条件
 * @param {!string} param.lovCode - 查询条件
 * @returns {object} fetch Promise
 */

function _queryCreateRolesSublist() {
  _queryCreateRolesSublist = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params, organizationId) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/").concat(organizationId === 0 ? '' : "".concat(organizationId, "/"), "member-roles/create-roles-sublist"), {
              query: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _queryCreateRolesSublist.apply(this, arguments);
}

export function queryCode() {
  return _queryCode.apply(this, arguments);
}

function _queryCode() {
  _queryCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
    var params,
        _args5 = arguments;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            params = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {};
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/lovs/value"), {
              query: params
            }));

          case 2:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _queryCode.apply(this, arguments);
}

export function createMember() {
  return _createMember.apply(this, arguments);
}

function _createMember() {
  _createMember = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
    var memberIds,
        params,
        organizationId,
        _args6 = arguments;
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            memberIds = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : [];
            params = _args6.length > 1 ? _args6[1] : undefined;
            organizationId = _args6.length > 2 ? _args6[2] : undefined;
            return _context6.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/").concat(organizationId, "/member-roles"), {
              method: 'POST',
              body: params,
              query: {
                memberIds: memberIds.toString()
              }
            }));

          case 4:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _createMember.apply(this, arguments);
}

export function batchAssign() {
  return _batchAssign.apply(this, arguments);
}

function _batchAssign() {
  _batchAssign = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
    var memberIds,
        params,
        isEdit,
        organizationId,
        _args7 = arguments;
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            memberIds = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : [];
            params = _args7.length > 1 ? _args7[1] : undefined;
            isEdit = _args7.length > 2 ? _args7[2] : undefined;
            organizationId = _args7.length > 3 ? _args7[3] : undefined;
            return _context7.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/").concat(organizationId === 0 ? '' : "".concat(organizationId, "/"), "member-roles/batch-assign"), {
              method: 'POST',
              body: params,
              query: {
                memberIds: memberIds.toString(),
                isEdit: isEdit
              }
            }));

          case 5:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _batchAssign.apply(this, arguments);
}

export function deleteMember() {
  return _deleteMember.apply(this, arguments);
}

function _deleteMember() {
  _deleteMember = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
    var params,
        _args8 = arguments;
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            params = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : {};
            return _context8.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/member-roles"), {
              method: 'DELETE',
              body: params
            }));

          case 2:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _deleteMember.apply(this, arguments);
}

export function deleteOrganizationMember() {
  return _deleteOrganizationMember.apply(this, arguments);
}

function _deleteOrganizationMember() {
  _deleteOrganizationMember = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
    var params,
        organizationId,
        _args9 = arguments;
    return _regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            params = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {};
            organizationId = _args9.length > 1 ? _args9[1] : undefined;
            return _context9.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/").concat(organizationId, "/member-roles"), {
              method: 'DELETE',
              body: params
            }));

          case 3:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _deleteOrganizationMember.apply(this, arguments);
}

export function queryHrunitsTree() {
  return _queryHrunitsTree.apply(this, arguments);
}

function _queryHrunitsTree() {
  _queryHrunitsTree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
    var params,
        organizationId,
        _args10 = arguments;
    return _regeneratorRuntime.wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            params = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : {};
            organizationId = _args10.length > 1 ? _args10[1] : undefined;
            return _context10.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/").concat(organizationId, "/hrunits/tree"), {
              query: params
            }));

          case 3:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10);
  }));
  return _queryHrunitsTree.apply(this, arguments);
}